/*
 * @Descripttion: GGB
 * @version: 1.0
 * @Author: GGB
 * @Date: 2021-08-17 13:32:21
 * @LastEditors: GGB
 * @LastEditTime: 2021-08-18 06:48:51
 */
import 'package:flutter/material.dart';
import 'package:flutter_data_center/controller/door_controller.dart';
import 'package:get/get.dart';
import './components/date_picker.dart';
import './components/door_detail_list.dart';
import './components/door_detail_menu.dart';
import './components/door_detail_statistics.dart';

class DoorDetailScreen extends StatefulWidget {
  const DoorDetailScreen({Key key, this.title}) : super(key: key);
  static String routeName = "/door_detail";
  final String title;

  @override
  _DoorDetailScreenState createState() => _DoorDetailScreenState();
}

class _DoorDetailScreenState extends State<DoorDetailScreen> {
  final keyWidget = GlobalKey();
  DoorController _doorController = Get.put(DoorController());
  DateTime _selectedDate;
  int currentIndex = 0;
  double height = 0;
  void calculateSizeAndPosition() =>
      WidgetsBinding.instance.addPostFrameCallback((_) {
        final RenderBox box =
            keyWidget.currentContext.findRenderObject(); // 包含widget的绘制信息
        setState(() {
          height = box.size.height + 90;
        });
      });
  @override
  void initState() {
    super.initState();
    calculateSizeAndPosition();
    _doorController.getDoorStatistics();
    _doorController.getPeople();
  }

  @override
  Widget build(BuildContext context) => Scaffold(
        appBar: AppBar(
          title: Text(widget.title),
          elevation: 0,
          centerTitle: true,
          backgroundColor: Colors.white,
        ),
        body: SafeArea(
            child: SingleChildScrollView(
          child: Padding(
            padding: const EdgeInsets.symmetric(horizontal: 27),
            child: Column(
              children: [
                Column(
                  key: keyWidget,
                  children: [
                    DatePicker(
                      selectedDate: _selectedDate,
                      onChange: (value) {
                        setState(() {
                          _selectedDate = value;
                        });
                      },
                    ),
                    DoorDetailStatistics(),
                    DoorDetailMenu(
                      currentIndex: currentIndex,
                      onChange: (value) {
                        setState(() {
                          currentIndex = value;
                        });
                      },
                    ),
                  ],
                ),
                Container(
                  height: MediaQuery.of(context).size.height - height,
                  child: DoorDetailList(),
                ),
              ],
            ),
          ),
        )),
      );
}
